import { Ref } from "vue";
interface ResetOnlyParam {
  form: Ref<any>;
  formInit: any;
  formRef: Ref<any>;
}
interface ResetParam extends ResetOnlyParam {
  conditionForm: Ref<any>;
  conditionFormRef: Ref<any>;
  request: any;
  other?: any;
}
export const useReset = (params: ResetParam) => {
  const {
    form,
    formInit,
    formRef,
    conditionForm,
    conditionFormRef,
    request,
    other,
  } = params;
  const reset = () => {
    form.value = formInit;
    console.log("formRef", formRef.value);
    if (formRef.value) {
      formRef.value.resetFields();
    }
  };
  const resetQuery = () => {
    if (conditionForm.value.dateTimes) {
      conditionForm.value.dateTimes = [];
    }
    if (conditionForm.value.dictType && other) {
      conditionForm.value.dictType = other;
    }
    if (conditionFormRef.value) {
      conditionFormRef.value.resetFields();
    }
    request();
  };
  const resetAll = () => {
    // 重置路由
    // router.push("/sysAdmin/dictSetting");
    // 重置表单
    // formRef.value?.resetFields();
    // 重置表格
    // tableRef.value?.clearSelection();
  };
  return { reset, resetQuery, resetAll };
};
// todo 重置表单
export const useResetOnly = (params: ResetOnlyParam) => {
  const { form, formInit, formRef } = params;
  const reset = () => {
    form.value = formInit;
    console.log("formRef", formRef.value);
    if (formRef.value) {
      formRef.value.resetFields();
    }
  };
  return { reset };
};
